package csc.com.app;

import java.util.List;
import java.util.Scanner;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import csc.com.dao.EmployeeDAO;
import csc.com.model.Employee;
import csc.com.service.EmployeeService;

public class EmployeeApp {

	private static ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
	
	private static EmployeeService employeeService = (EmployeeService) context.getBean("employeeService");

	public static void main(String[] args) {

		System.out.println("1. Print a list of employees");
		System.out.println("2. Add a employee");
		System.out.println("3. Delele a employee");
		System.out.println("4. Quit");
		int choose;

		boolean stop = false;
		while (!stop) {
			System.out.print("Choose : ");
			Scanner input = new Scanner(System.in);
			choose = input.nextInt();
			switch (choose) {
			case 1:
				printListEmployee();
				break;
			case 2:
				addEmployee();
				break;
			case 3:
				deleteEmployee();
				break;
			case 4:
				stop = true;
				System.out.println("Quit !");
				break;

			}
		}

	}

	public static void printListEmployee() {

		List<Employee> employees = employeeService.getEmployees();
		for (Employee record : employees) {
			System.out.println("------------------------------");
			System.out.println("ID : " + record.getEmployeeId());
			System.out.println("Name : " + record.getName());
			System.out.println("Address : " + record.getAddress());
			System.out.println("Phone : " + record.getPhone());
			System.out.println("Email : " + record.getEmail());
		}
	}

	public static void addEmployee() {
		Scanner input = new Scanner(System.in);
		System.out.println("please enter employeeId : ");
		String id = input.nextLine();
		System.out.println("please enter name : ");
		String name = input.nextLine();
		System.out.println("please enter address : ");
		String address = input.nextLine();
		System.out.println("please enter phone : ");
		String phone = input.nextLine();
		System.out.println("please enter email : ");
		String email = input.nextLine();
		// add
		employeeService.addEmployee(id, name, address, phone, email);
		System.out.println("Done");

	}

	public static void deleteEmployee() {
		Scanner input = new Scanner(System.in);
		System.out.print("please enter employeeId : ");
		String id = input.nextLine();
		// delete
		employeeService.deleteEmployee(id);
		System.out.println("Done");
	}
}
